<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//function get_degree_list() {
//    select_itec_database();
//    $list = array();
//    $sql = db_query("call sp_GetDegreeList()");
//    while($temp = $sql->fetchAssoc()) {
//        $list[] = $temp;
//    }
//    select_drupal_database();
//    
//    return $list;
//}

function get_rank_list() {
    select_itec_database();
    $list = array();
    $sql = db_query("call sp_GetRankList()");
    while($temp = $sql->fetchAssoc()) {
        if($temp == NULL)
            break;
        $list[] = $temp['name'];
    }
    select_drupal_database();
    
    return $list;
}

function get_lecturer_status_list() {
    select_itec_database();
    $list = array();
    $sql = db_query("call sp_GetLecturerStatusList()");
    while($temp = $sql->fetchAssoc()) {
        if($temp == NULL)
            break;
        $list[] = $temp['description'];
    }
    select_drupal_database();
    
    return $list;
}

function add_lecturer($fname, $lname, $dob, $gender, $status,  $deg, $rank, $email, $phone, $hp, $n){
    select_itec_database();
    $sql = db_query("call sp_AddLecturer('".$fname."','".$lname."','".$dob."','".$gender."','".$status."','".$deg."','".$rank."','".$email."','".$phone."','".$hp."','".$n."')");
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['result'];
}

function update_lecturer($id, $fname, $lname, $dob, $gender, $status,  $deg, $rank, $email, $phone, $hp, $n){
    select_itec_database();
    $sql = db_query("call sp_UpdateLecturerInfo('".$id."','".$fname."','".$lname."','".$dob."',".$gender.",'".$status."','".$deg."','".$rank."','".$email."','".$phone."','".$hp."','".$n."')");
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['result'];
}

function get_degree_id_from_name($name) {
    select_itec_database();
    $sql = db_query("select degreeid from degree where name = '".$name."'");
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['degreeid'];
}

function get_rank_id_from_name($irow) {
    select_itec_database();
    $result = array();
    $sql = db_query("select rankid from rank");
    
    for($i = 1; $i <= $irow; $i++)
        $result = $sql->fetchAssoc();
    
    select_drupal_database();
    return $result['rankid'];
}

function get_lecturer_info_from_id($id) {
    select_itec_database();
    $sql = db_query("call sp_ViewLecturerInfo('".$id."')");
    $result = $sql->fetchAssoc();
    return $result;
    select_drupal_database();
}

function get_degree_name($id) {
    select_itec_database();
    $sql = db_query("call sp_GetDegreeName('".$id."')");
    $result = $sql->fetchAssoc();
    
    return $result;
    select_drupal_database();
}

?>
